package cn.zhouchao.basic.dto;

import cn.zhouchao.basic.util.MD5Utils;
import cn.zhouchao.basic.util.StrUtils;
import cn.zhouchao.user.domain.User;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import java.util.Date;

@Data
public class BinderDto {
    @NotBlank(message = "phone 不能为空！")
    private String phone;
    @NotBlank(message = "verifyCode 不能为空！") // 验证码：verify
    private String verifyCode;
    @NotBlank(message = "accessToken 不能为空！")
    private String accessToken;
    @NotBlank(message = "openId 不能为空！")
    private String openId;

    /**
     * 获取都不为空正确的字段值，并添加给user对象
     * @return
     */
    public User getUser(){
        String salt = StrUtils.getComplexRandomString(32);
        String passwords = MD5Utils.encrypByMd5(salt+"1"); // 默认密码
        return User.builder()
                .username(this.phone)
                .phone(this.phone)
                .salt(salt)
                .password(passwords)
                .state(1)
                .createtime(new Date())
                .build();
    }
}
